<?php

/**
 * GetNodeListApi.class.php 
 * 
 *
 * @author     late.xiao@qq.com
 */
namespace Sysblog\Api;

use Base\Lib\Implement\Api;

class GetNodeListApi implements Api {

    public $api_desc = '根据条件获取类目列表';
    public function getParams()
    {
        $params = array(
                'node_id'=>array('type'=>'string','valid'=>'', 'default'=>'', 'title'=>'类目ID集合', 'example'=>'1,2 | 2'),
                'parent_id'=>array('type'=>'int','valid'=>'', 'default'=>'', 'title'=>'父类ID'),
                'fields'=>array('type'=>'string','valid'=>'', 'default'=>'*', 'title'=>'返回的字段'),
        );
        
        return $params;
    }
    
    public function getList($params)
    {
        $filter = array();
        if($params['node_id'])
        {
            $node_ids = explode(',', $params['node_id']);
            if(count($node_ids) == 1)
            {
                $filter['node_id'] = intval($node_ids[0]);
            }
            else
            {
                $filter['node_id'] = array('in', $node_ids);
            }
        }
        
        
        
        if($params['parent_id'])
        {
            $filter['parent_id'] = intval($params['parent_id']);
        }
        
        $field = '*';
        if($params['fields'])
        {
            $field = $params['fields'];
            if(!strstr($field, 'parent_id'))
            {
                $field = $field.',parent_id';
            }
        }
        
        $obj_serv = D('Sysblog/Category', 'Service');
        $data = $obj_serv->getCatList($field, $filter);
        $data = $obj_serv->proCatList($data);
        
        return $data;
    }

}
 